/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.service.persistence;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
import com.liferay.portal.kernel.dao.jdbc.RowMapper;
import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.SetUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import vn.com.fis.portal.NoSuchUserEntryException;
import vn.com.fis.portal.model.UserEntry;
import vn.com.fis.portal.model.impl.UserEntryImpl;
import vn.com.fis.portal.model.impl.UserEntryModelImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

/**
 * The persistence implementation for the user entry service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author loind
 * @see UserEntryPersistence
 * @see UserEntryUtil
 * @generated
 */
public class UserEntryPersistenceImpl extends BasePersistenceImpl<UserEntry>
	implements UserEntryPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link UserEntryUtil} to access the user entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = UserEntryImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SERVICEID =
		new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, UserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByServiceId",
			new String[] {
				Long.class.getName(),
				
			"java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SERVICEID =
		new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, UserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByServiceId",
			new String[] { Long.class.getName() },
			UserEntryModelImpl.SERVICEID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_SERVICEID = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByServiceId",
			new String[] { Long.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_USERNAME = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, UserEntryImpl.class,
			FINDER_CLASS_NAME_ENTITY, "fetchByUserName",
			new String[] { String.class.getName() },
			UserEntryModelImpl.USERNAME_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_USERNAME = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserName",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_MOBILEPHONE = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, UserEntryImpl.class,
			FINDER_CLASS_NAME_ENTITY, "fetchByMobilePhone",
			new String[] { String.class.getName() },
			UserEntryModelImpl.MOBILEPHONE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_MOBILEPHONE = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByMobilePhone",
			new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, UserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, UserEntryImpl.class,
			FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the user entry in the entity cache if it is enabled.
	 *
	 * @param userEntry the user entry
	 */
	public void cacheResult(UserEntry userEntry) {
		EntityCacheUtil.putResult(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryImpl.class, userEntry.getPrimaryKey(), userEntry);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERNAME,
			new Object[] { userEntry.getUserName() }, userEntry);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
			new Object[] { userEntry.getMobilePhone() }, userEntry);

		userEntry.resetOriginalValues();
	}

	/**
	 * Caches the user entries in the entity cache if it is enabled.
	 *
	 * @param userEntries the user entries
	 */
	public void cacheResult(List<UserEntry> userEntries) {
		for (UserEntry userEntry : userEntries) {
			if (EntityCacheUtil.getResult(
						UserEntryModelImpl.ENTITY_CACHE_ENABLED,
						UserEntryImpl.class, userEntry.getPrimaryKey()) == null) {
				cacheResult(userEntry);
			}
			else {
				userEntry.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all user entries.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(UserEntryImpl.class.getName());
		}

		EntityCacheUtil.clearCache(UserEntryImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the user entry.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(UserEntry userEntry) {
		EntityCacheUtil.removeResult(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryImpl.class, userEntry.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache(userEntry);
	}

	@Override
	public void clearCache(List<UserEntry> userEntries) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (UserEntry userEntry : userEntries) {
			EntityCacheUtil.removeResult(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
				UserEntryImpl.class, userEntry.getPrimaryKey());

			clearUniqueFindersCache(userEntry);
		}
	}

	protected void clearUniqueFindersCache(UserEntry userEntry) {
		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERNAME,
			new Object[] { userEntry.getUserName() });

		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
			new Object[] { userEntry.getMobilePhone() });
	}

	/**
	 * Creates a new user entry with the primary key. Does not add the user entry to the database.
	 *
	 * @param userId the primary key for the new user entry
	 * @return the new user entry
	 */
	public UserEntry create(long userId) {
		UserEntry userEntry = new UserEntryImpl();

		userEntry.setNew(true);
		userEntry.setPrimaryKey(userId);

		return userEntry;
	}

	/**
	 * Removes the user entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param userId the primary key of the user entry
	 * @return the user entry that was removed
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry remove(long userId)
		throws NoSuchUserEntryException, SystemException {
		return remove(Long.valueOf(userId));
	}

	/**
	 * Removes the user entry with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the user entry
	 * @return the user entry that was removed
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public UserEntry remove(Serializable primaryKey)
		throws NoSuchUserEntryException, SystemException {
		Session session = null;

		try {
			session = openSession();

			UserEntry userEntry = (UserEntry)session.get(UserEntryImpl.class,
					primaryKey);

			if (userEntry == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchUserEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(userEntry);
		}
		catch (NoSuchUserEntryException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected UserEntry removeImpl(UserEntry userEntry)
		throws SystemException {
		userEntry = toUnwrappedModel(userEntry);

		try {
			clearVideoEntries.clear(userEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, userEntry);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(userEntry);

		return userEntry;
	}

	@Override
	public UserEntry updateImpl(vn.com.fis.portal.model.UserEntry userEntry,
		boolean merge) throws SystemException {
		userEntry = toUnwrappedModel(userEntry);

		boolean isNew = userEntry.isNew();

		UserEntryModelImpl userEntryModelImpl = (UserEntryModelImpl)userEntry;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, userEntry, merge);

			userEntry.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !UserEntryModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		else {
			if ((userEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SERVICEID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(userEntryModelImpl.getOriginalServiceId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVICEID,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SERVICEID,
					args);

				args = new Object[] {
						Long.valueOf(userEntryModelImpl.getServiceId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SERVICEID,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SERVICEID,
					args);
			}
		}

		EntityCacheUtil.putResult(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryImpl.class, userEntry.getPrimaryKey(), userEntry);

		if (isNew) {
			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERNAME,
				new Object[] { userEntry.getUserName() }, userEntry);

			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
				new Object[] { userEntry.getMobilePhone() }, userEntry);
		}
		else {
			if ((userEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_USERNAME.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						userEntryModelImpl.getOriginalUserName()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERNAME, args);
				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERNAME, args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERNAME,
					new Object[] { userEntry.getUserName() }, userEntry);
			}

			if ((userEntryModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_MOBILEPHONE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						userEntryModelImpl.getOriginalMobilePhone()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_MOBILEPHONE,
					args);
				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
					args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
					new Object[] { userEntry.getMobilePhone() }, userEntry);
			}
		}

		return userEntry;
	}

	protected UserEntry toUnwrappedModel(UserEntry userEntry) {
		if (userEntry instanceof UserEntryImpl) {
			return userEntry;
		}

		UserEntryImpl userEntryImpl = new UserEntryImpl();

		userEntryImpl.setNew(userEntry.isNew());
		userEntryImpl.setPrimaryKey(userEntry.getPrimaryKey());

		userEntryImpl.setUserId(userEntry.getUserId());
		userEntryImpl.setUserName(userEntry.getUserName());
		userEntryImpl.setMobilePhone(userEntry.getMobilePhone());
		userEntryImpl.setGroupId(userEntry.getGroupId());
		userEntryImpl.setCompanyId(userEntry.getCompanyId());
		userEntryImpl.setServiceId(userEntry.getServiceId());
		userEntryImpl.setServiceStatus(userEntry.getServiceStatus());
		userEntryImpl.setServiceStartDate(userEntry.getServiceStartDate());
		userEntryImpl.setServiceStopDate(userEntry.getServiceStopDate());
		userEntryImpl.setServicePackageId(userEntry.getServicePackageId());
		userEntryImpl.setServicePackageStatus(userEntry.getServicePackageStatus());
		userEntryImpl.setServicePackageStartDate(userEntry.getServicePackageStartDate());
		userEntryImpl.setCreateDate(userEntry.getCreateDate());
		userEntryImpl.setModifiedDate(userEntry.getModifiedDate());
		userEntryImpl.setDescription(userEntry.getDescription());
		userEntryImpl.setStatus(userEntry.getStatus());

		return userEntryImpl;
	}

	/**
	 * Returns the user entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the user entry
	 * @return the user entry
	 * @throws com.liferay.portal.NoSuchModelException if a user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public UserEntry findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the user entry with the primary key or throws a {@link vn.com.fis.portal.NoSuchUserEntryException} if it could not be found.
	 *
	 * @param userId the primary key of the user entry
	 * @return the user entry
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry findByPrimaryKey(long userId)
		throws NoSuchUserEntryException, SystemException {
		UserEntry userEntry = fetchByPrimaryKey(userId);

		if (userEntry == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userId);
			}

			throw new NoSuchUserEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				userId);
		}

		return userEntry;
	}

	/**
	 * Returns the user entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the user entry
	 * @return the user entry, or <code>null</code> if a user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public UserEntry fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the user entry with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param userId the primary key of the user entry
	 * @return the user entry, or <code>null</code> if a user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry fetchByPrimaryKey(long userId) throws SystemException {
		UserEntry userEntry = (UserEntry)EntityCacheUtil.getResult(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
				UserEntryImpl.class, userId);

		if (userEntry == _nullUserEntry) {
			return null;
		}

		if (userEntry == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				userEntry = (UserEntry)session.get(UserEntryImpl.class,
						Long.valueOf(userId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (userEntry != null) {
					cacheResult(userEntry);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(UserEntryModelImpl.ENTITY_CACHE_ENABLED,
						UserEntryImpl.class, userId, _nullUserEntry);
				}

				closeSession(session);
			}
		}

		return userEntry;
	}

	/**
	 * Returns all the user entries where serviceId = &#63;.
	 *
	 * @param serviceId the service ID
	 * @return the matching user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<UserEntry> findByServiceId(long serviceId)
		throws SystemException {
		return findByServiceId(serviceId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
			null);
	}

	/**
	 * Returns a range of all the user entries where serviceId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param serviceId the service ID
	 * @param start the lower bound of the range of user entries
	 * @param end the upper bound of the range of user entries (not inclusive)
	 * @return the range of matching user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<UserEntry> findByServiceId(long serviceId, int start, int end)
		throws SystemException {
		return findByServiceId(serviceId, start, end, null);
	}

	/**
	 * Returns an ordered range of all the user entries where serviceId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param serviceId the service ID
	 * @param start the lower bound of the range of user entries
	 * @param end the upper bound of the range of user entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of matching user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<UserEntry> findByServiceId(long serviceId, int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = null;

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SERVICEID;
			finderArgs = new Object[] { serviceId };
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SERVICEID;
			finderArgs = new Object[] { serviceId, start, end, orderByComparator };
		}

		List<UserEntry> list = (List<UserEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;

			if (orderByComparator != null) {
				query = new StringBundler(3 +
						(orderByComparator.getOrderByFields().length * 3));
			}
			else {
				query = new StringBundler(3);
			}

			query.append(_SQL_SELECT_USERENTRY_WHERE);

			query.append(_FINDER_COLUMN_SERVICEID_SERVICEID_2);

			if (orderByComparator != null) {
				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);
			}

			else {
				query.append(UserEntryModelImpl.ORDER_BY_JPQL);
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(serviceId);

				list = (List<UserEntry>)QueryUtil.list(q, getDialect(), start,
						end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Returns the first user entry in the ordered set where serviceId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param serviceId the service ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the first matching user entry
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry findByServiceId_First(long serviceId,
		OrderByComparator orderByComparator)
		throws NoSuchUserEntryException, SystemException {
		List<UserEntry> list = findByServiceId(serviceId, 0, 1,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("serviceId=");
			msg.append(serviceId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the last user entry in the ordered set where serviceId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param serviceId the service ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the last matching user entry
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry findByServiceId_Last(long serviceId,
		OrderByComparator orderByComparator)
		throws NoSuchUserEntryException, SystemException {
		int count = countByServiceId(serviceId);

		List<UserEntry> list = findByServiceId(serviceId, count - 1, count,
				orderByComparator);

		if (list.isEmpty()) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("serviceId=");
			msg.append(serviceId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			throw new NoSuchUserEntryException(msg.toString());
		}
		else {
			return list.get(0);
		}
	}

	/**
	 * Returns the user entries before and after the current user entry in the ordered set where serviceId = &#63;.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param userId the primary key of the current user entry
	 * @param serviceId the service ID
	 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
	 * @return the previous, current, and next user entry
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a user entry with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry[] findByServiceId_PrevAndNext(long userId, long serviceId,
		OrderByComparator orderByComparator)
		throws NoSuchUserEntryException, SystemException {
		UserEntry userEntry = findByPrimaryKey(userId);

		Session session = null;

		try {
			session = openSession();

			UserEntry[] array = new UserEntryImpl[3];

			array[0] = getByServiceId_PrevAndNext(session, userEntry,
					serviceId, orderByComparator, true);

			array[1] = userEntry;

			array[2] = getByServiceId_PrevAndNext(session, userEntry,
					serviceId, orderByComparator, false);

			return array;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	protected UserEntry getByServiceId_PrevAndNext(Session session,
		UserEntry userEntry, long serviceId,
		OrderByComparator orderByComparator, boolean previous) {
		StringBundler query = null;

		if (orderByComparator != null) {
			query = new StringBundler(6 +
					(orderByComparator.getOrderByFields().length * 6));
		}
		else {
			query = new StringBundler(3);
		}

		query.append(_SQL_SELECT_USERENTRY_WHERE);

		query.append(_FINDER_COLUMN_SERVICEID_SERVICEID_2);

		if (orderByComparator != null) {
			String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

			if (orderByConditionFields.length > 0) {
				query.append(WHERE_AND);
			}

			for (int i = 0; i < orderByConditionFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByConditionFields[i]);

				if ((i + 1) < orderByConditionFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN_HAS_NEXT);
					}
					else {
						query.append(WHERE_LESSER_THAN_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(WHERE_GREATER_THAN);
					}
					else {
						query.append(WHERE_LESSER_THAN);
					}
				}
			}

			query.append(ORDER_BY_CLAUSE);

			String[] orderByFields = orderByComparator.getOrderByFields();

			for (int i = 0; i < orderByFields.length; i++) {
				query.append(_ORDER_BY_ENTITY_ALIAS);
				query.append(orderByFields[i]);

				if ((i + 1) < orderByFields.length) {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC_HAS_NEXT);
					}
					else {
						query.append(ORDER_BY_DESC_HAS_NEXT);
					}
				}
				else {
					if (orderByComparator.isAscending() ^ previous) {
						query.append(ORDER_BY_ASC);
					}
					else {
						query.append(ORDER_BY_DESC);
					}
				}
			}
		}

		else {
			query.append(UserEntryModelImpl.ORDER_BY_JPQL);
		}

		String sql = query.toString();

		Query q = session.createQuery(sql);

		q.setFirstResult(0);
		q.setMaxResults(2);

		QueryPos qPos = QueryPos.getInstance(q);

		qPos.add(serviceId);

		if (orderByComparator != null) {
			Object[] values = orderByComparator.getOrderByConditionValues(userEntry);

			for (Object value : values) {
				qPos.add(value);
			}
		}

		List<UserEntry> list = q.list();

		if (list.size() == 2) {
			return list.get(1);
		}
		else {
			return null;
		}
	}

	/**
	 * Returns the user entry where userName = &#63; or throws a {@link vn.com.fis.portal.NoSuchUserEntryException} if it could not be found.
	 *
	 * @param userName the user name
	 * @return the matching user entry
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry findByUserName(String userName)
		throws NoSuchUserEntryException, SystemException {
		UserEntry userEntry = fetchByUserName(userName);

		if (userEntry == null) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("userName=");
			msg.append(userName);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchUserEntryException(msg.toString());
		}

		return userEntry;
	}

	/**
	 * Returns the user entry where userName = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param userName the user name
	 * @return the matching user entry, or <code>null</code> if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry fetchByUserName(String userName) throws SystemException {
		return fetchByUserName(userName, true);
	}

	/**
	 * Returns the user entry where userName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param userName the user name
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching user entry, or <code>null</code> if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry fetchByUserName(String userName, boolean retrieveFromCache)
		throws SystemException {
		Object[] finderArgs = new Object[] { userName };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_USERNAME,
					finderArgs, this);
		}

		if (result == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_SELECT_USERENTRY_WHERE);

			if (userName == null) {
				query.append(_FINDER_COLUMN_USERNAME_USERNAME_1);
			}
			else {
				if (userName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_USERNAME_USERNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_USERNAME_USERNAME_2);
				}
			}

			query.append(UserEntryModelImpl.ORDER_BY_JPQL);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (userName != null) {
					qPos.add(userName);
				}

				List<UserEntry> list = q.list();

				result = list;

				UserEntry userEntry = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERNAME,
						finderArgs, list);
				}
				else {
					userEntry = list.get(0);

					cacheResult(userEntry);

					if ((userEntry.getUserName() == null) ||
							!userEntry.getUserName().equals(userName)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_USERNAME,
							finderArgs, userEntry);
					}
				}

				return userEntry;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_USERNAME,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (UserEntry)result;
			}
		}
	}

	/**
	 * Returns the user entry where mobilePhone = &#63; or throws a {@link vn.com.fis.portal.NoSuchUserEntryException} if it could not be found.
	 *
	 * @param mobilePhone the mobile phone
	 * @return the matching user entry
	 * @throws vn.com.fis.portal.NoSuchUserEntryException if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry findByMobilePhone(String mobilePhone)
		throws NoSuchUserEntryException, SystemException {
		UserEntry userEntry = fetchByMobilePhone(mobilePhone);

		if (userEntry == null) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("mobilePhone=");
			msg.append(mobilePhone);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchUserEntryException(msg.toString());
		}

		return userEntry;
	}

	/**
	 * Returns the user entry where mobilePhone = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param mobilePhone the mobile phone
	 * @return the matching user entry, or <code>null</code> if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry fetchByMobilePhone(String mobilePhone)
		throws SystemException {
		return fetchByMobilePhone(mobilePhone, true);
	}

	/**
	 * Returns the user entry where mobilePhone = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param mobilePhone the mobile phone
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching user entry, or <code>null</code> if a matching user entry could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public UserEntry fetchByMobilePhone(String mobilePhone,
		boolean retrieveFromCache) throws SystemException {
		Object[] finderArgs = new Object[] { mobilePhone };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
					finderArgs, this);
		}

		if (result == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_SELECT_USERENTRY_WHERE);

			if (mobilePhone == null) {
				query.append(_FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_1);
			}
			else {
				if (mobilePhone.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_3);
				}
				else {
					query.append(_FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_2);
				}
			}

			query.append(UserEntryModelImpl.ORDER_BY_JPQL);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (mobilePhone != null) {
					qPos.add(mobilePhone);
				}

				List<UserEntry> list = q.list();

				result = list;

				UserEntry userEntry = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
						finderArgs, list);
				}
				else {
					userEntry = list.get(0);

					cacheResult(userEntry);

					if ((userEntry.getMobilePhone() == null) ||
							!userEntry.getMobilePhone().equals(mobilePhone)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
							finderArgs, userEntry);
					}
				}

				return userEntry;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_MOBILEPHONE,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (UserEntry)result;
			}
		}
	}

	/**
	 * Returns all the user entries.
	 *
	 * @return the user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<UserEntry> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the user entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of user entries
	 * @param end the upper bound of the range of user entries (not inclusive)
	 * @return the range of user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<UserEntry> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the user entries.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of user entries
	 * @param end the upper bound of the range of user entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of user entries
	 * @throws SystemException if a system exception occurred
	 */
	public List<UserEntry> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<UserEntry> list = (List<UserEntry>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_USERENTRY);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_USERENTRY.concat(UserEntryModelImpl.ORDER_BY_JPQL);
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<UserEntry>)QueryUtil.list(q, getDialect(),
							start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<UserEntry>)QueryUtil.list(q, getDialect(),
							start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes all the user entries where serviceId = &#63; from the database.
	 *
	 * @param serviceId the service ID
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByServiceId(long serviceId) throws SystemException {
		for (UserEntry userEntry : findByServiceId(serviceId)) {
			remove(userEntry);
		}
	}

	/**
	 * Removes the user entry where userName = &#63; from the database.
	 *
	 * @param userName the user name
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByUserName(String userName)
		throws NoSuchUserEntryException, SystemException {
		UserEntry userEntry = findByUserName(userName);

		remove(userEntry);
	}

	/**
	 * Removes the user entry where mobilePhone = &#63; from the database.
	 *
	 * @param mobilePhone the mobile phone
	 * @throws SystemException if a system exception occurred
	 */
	public void removeByMobilePhone(String mobilePhone)
		throws NoSuchUserEntryException, SystemException {
		UserEntry userEntry = findByMobilePhone(mobilePhone);

		remove(userEntry);
	}

	/**
	 * Removes all the user entries from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (UserEntry userEntry : findAll()) {
			remove(userEntry);
		}
	}

	/**
	 * Returns the number of user entries where serviceId = &#63;.
	 *
	 * @param serviceId the service ID
	 * @return the number of matching user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByServiceId(long serviceId) throws SystemException {
		Object[] finderArgs = new Object[] { serviceId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SERVICEID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_USERENTRY_WHERE);

			query.append(_FINDER_COLUMN_SERVICEID_SERVICEID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(serviceId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SERVICEID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of user entries where userName = &#63;.
	 *
	 * @param userName the user name
	 * @return the number of matching user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByUserName(String userName) throws SystemException {
		Object[] finderArgs = new Object[] { userName };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERNAME,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_USERENTRY_WHERE);

			if (userName == null) {
				query.append(_FINDER_COLUMN_USERNAME_USERNAME_1);
			}
			else {
				if (userName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_USERNAME_USERNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_USERNAME_USERNAME_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (userName != null) {
					qPos.add(userName);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERNAME,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of user entries where mobilePhone = &#63;.
	 *
	 * @param mobilePhone the mobile phone
	 * @return the number of matching user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countByMobilePhone(String mobilePhone) throws SystemException {
		Object[] finderArgs = new Object[] { mobilePhone };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MOBILEPHONE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_USERENTRY_WHERE);

			if (mobilePhone == null) {
				query.append(_FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_1);
			}
			else {
				if (mobilePhone.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_3);
				}
				else {
					query.append(_FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (mobilePhone != null) {
					qPos.add(mobilePhone);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MOBILEPHONE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of user entries.
	 *
	 * @return the number of user entries
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_USERENTRY);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns all the video entries associated with the user entry.
	 *
	 * @param pk the primary key of the user entry
	 * @return the video entries associated with the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.VideoEntry> getVideoEntries(long pk)
		throws SystemException {
		return getVideoEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	}

	/**
	 * Returns a range of all the video entries associated with the user entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the user entry
	 * @param start the lower bound of the range of user entries
	 * @param end the upper bound of the range of user entries (not inclusive)
	 * @return the range of video entries associated with the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.VideoEntry> getVideoEntries(long pk,
		int start, int end) throws SystemException {
		return getVideoEntries(pk, start, end, null);
	}

	public static final FinderPath FINDER_PATH_GET_VIDEOENTRIES = new FinderPath(vn.com.fis.portal.model.impl.VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED_TBL_VIDEO_USER,
			vn.com.fis.portal.model.impl.VideoEntryImpl.class,
			UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME,
			"getVideoEntries",
			new String[] {
				Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
				"com.liferay.portal.kernel.util.OrderByComparator"
			});

	/**
	 * Returns an ordered range of all the video entries associated with the user entry.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param pk the primary key of the user entry
	 * @param start the lower bound of the range of user entries
	 * @param end the upper bound of the range of user entries (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of video entries associated with the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public List<vn.com.fis.portal.model.VideoEntry> getVideoEntries(long pk,
		int start, int end, OrderByComparator orderByComparator)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };

		List<vn.com.fis.portal.model.VideoEntry> list = (List<vn.com.fis.portal.model.VideoEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_VIDEOENTRIES,
				finderArgs, this);

		if (list == null) {
			Session session = null;

			try {
				session = openSession();

				String sql = null;

				if (orderByComparator != null) {
					sql = _SQL_GETVIDEOENTRIES.concat(ORDER_BY_CLAUSE)
											  .concat(orderByComparator.getOrderBy());
				}
				else {
					sql = _SQL_GETVIDEOENTRIES.concat(vn.com.fis.portal.model.impl.VideoEntryModelImpl.ORDER_BY_SQL);
				}

				SQLQuery q = session.createSQLQuery(sql);

				q.addEntity("tbl_video",
					vn.com.fis.portal.model.impl.VideoEntryImpl.class);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				list = (List<vn.com.fis.portal.model.VideoEntry>)QueryUtil.list(q,
						getDialect(), start, end);
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_GET_VIDEOENTRIES,
						finderArgs);
				}
				else {
					videoEntryPersistence.cacheResult(list);

					FinderCacheUtil.putResult(FINDER_PATH_GET_VIDEOENTRIES,
						finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	public static final FinderPath FINDER_PATH_GET_VIDEOENTRIES_SIZE = new FinderPath(vn.com.fis.portal.model.impl.VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED_TBL_VIDEO_USER, Long.class,
			UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME,
			"getVideoEntriesSize", new String[] { Long.class.getName() });

	/**
	 * Returns the number of video entries associated with the user entry.
	 *
	 * @param pk the primary key of the user entry
	 * @return the number of video entries associated with the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public int getVideoEntriesSize(long pk) throws SystemException {
		Object[] finderArgs = new Object[] { pk };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_VIDEOENTRIES_SIZE,
				finderArgs, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				SQLQuery q = session.createSQLQuery(_SQL_GETVIDEOENTRIESSIZE);

				q.addScalar(COUNT_COLUMN_NAME,
					com.liferay.portal.kernel.dao.orm.Type.LONG);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(pk);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_GET_VIDEOENTRIES_SIZE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	public static final FinderPath FINDER_PATH_CONTAINS_VIDEOENTRY = new FinderPath(vn.com.fis.portal.model.impl.VideoEntryModelImpl.ENTITY_CACHE_ENABLED,
			UserEntryModelImpl.FINDER_CACHE_ENABLED_TBL_VIDEO_USER,
			Boolean.class,
			UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME,
			"containsVideoEntry",
			new String[] { Long.class.getName(), Long.class.getName() });

	/**
	 * Returns <code>true</code> if the video entry is associated with the user entry.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntryPK the primary key of the video entry
	 * @return <code>true</code> if the video entry is associated with the user entry; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsVideoEntry(long pk, long videoEntryPK)
		throws SystemException {
		Object[] finderArgs = new Object[] { pk, videoEntryPK };

		Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_VIDEOENTRY,
				finderArgs, this);

		if (value == null) {
			try {
				value = Boolean.valueOf(containsVideoEntry.contains(pk,
							videoEntryPK));
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (value == null) {
					value = Boolean.FALSE;
				}

				FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_VIDEOENTRY,
					finderArgs, value);
			}
		}

		return value.booleanValue();
	}

	/**
	 * Returns <code>true</code> if the user entry has any video entries associated with it.
	 *
	 * @param pk the primary key of the user entry to check for associations with video entries
	 * @return <code>true</code> if the user entry has any video entries associated with it; <code>false</code> otherwise
	 * @throws SystemException if a system exception occurred
	 */
	public boolean containsVideoEntries(long pk) throws SystemException {
		if (getVideoEntriesSize(pk) > 0) {
			return true;
		}
		else {
			return false;
		}
	}

	/**
	 * Adds an association between the user entry and the video entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntryPK the primary key of the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void addVideoEntry(long pk, long videoEntryPK)
		throws SystemException {
		try {
			addVideoEntry.add(pk, videoEntryPK);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Adds an association between the user entry and the video entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntry the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void addVideoEntry(long pk,
		vn.com.fis.portal.model.VideoEntry videoEntry)
		throws SystemException {
		try {
			addVideoEntry.add(pk, videoEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Adds an association between the user entry and the video entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntryPKs the primary keys of the video entries
	 * @throws SystemException if a system exception occurred
	 */
	public void addVideoEntries(long pk, long[] videoEntryPKs)
		throws SystemException {
		try {
			for (long videoEntryPK : videoEntryPKs) {
				addVideoEntry.add(pk, videoEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Adds an association between the user entry and the video entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntries the video entries
	 * @throws SystemException if a system exception occurred
	 */
	public void addVideoEntries(long pk,
		List<vn.com.fis.portal.model.VideoEntry> videoEntries)
		throws SystemException {
		try {
			for (vn.com.fis.portal.model.VideoEntry videoEntry : videoEntries) {
				addVideoEntry.add(pk, videoEntry.getPrimaryKey());
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Clears all associations between the user entry and its video entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry to clear the associated video entries from
	 * @throws SystemException if a system exception occurred
	 */
	public void clearVideoEntries(long pk) throws SystemException {
		try {
			clearVideoEntries.clear(pk);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the user entry and the video entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntryPK the primary key of the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void removeVideoEntry(long pk, long videoEntryPK)
		throws SystemException {
		try {
			removeVideoEntry.remove(pk, videoEntryPK);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the user entry and the video entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntry the video entry
	 * @throws SystemException if a system exception occurred
	 */
	public void removeVideoEntry(long pk,
		vn.com.fis.portal.model.VideoEntry videoEntry)
		throws SystemException {
		try {
			removeVideoEntry.remove(pk, videoEntry.getPrimaryKey());
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the user entry and the video entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntryPKs the primary keys of the video entries
	 * @throws SystemException if a system exception occurred
	 */
	public void removeVideoEntries(long pk, long[] videoEntryPKs)
		throws SystemException {
		try {
			for (long videoEntryPK : videoEntryPKs) {
				removeVideoEntry.remove(pk, videoEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Removes the association between the user entry and the video entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntries the video entries
	 * @throws SystemException if a system exception occurred
	 */
	public void removeVideoEntries(long pk,
		List<vn.com.fis.portal.model.VideoEntry> videoEntries)
		throws SystemException {
		try {
			for (vn.com.fis.portal.model.VideoEntry videoEntry : videoEntries) {
				removeVideoEntry.remove(pk, videoEntry.getPrimaryKey());
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Sets the video entries associated with the user entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntryPKs the primary keys of the video entries to be associated with the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public void setVideoEntries(long pk, long[] videoEntryPKs)
		throws SystemException {
		try {
			Set<Long> videoEntryPKSet = SetUtil.fromArray(videoEntryPKs);

			List<vn.com.fis.portal.model.VideoEntry> videoEntries = getVideoEntries(pk);

			for (vn.com.fis.portal.model.VideoEntry videoEntry : videoEntries) {
				if (!videoEntryPKSet.remove(videoEntry.getPrimaryKey())) {
					removeVideoEntry.remove(pk, videoEntry.getPrimaryKey());
				}
			}

			for (Long videoEntryPK : videoEntryPKSet) {
				addVideoEntry.add(pk, videoEntryPK);
			}
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Sets the video entries associated with the user entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
	 *
	 * @param pk the primary key of the user entry
	 * @param videoEntries the video entries to be associated with the user entry
	 * @throws SystemException if a system exception occurred
	 */
	public void setVideoEntries(long pk,
		List<vn.com.fis.portal.model.VideoEntry> videoEntries)
		throws SystemException {
		try {
			long[] videoEntryPKs = new long[videoEntries.size()];

			for (int i = 0; i < videoEntries.size(); i++) {
				vn.com.fis.portal.model.VideoEntry videoEntry = videoEntries.get(i);

				videoEntryPKs[i] = videoEntry.getPrimaryKey();
			}

			setVideoEntries(pk, videoEntryPKs);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			FinderCacheUtil.clearCache(UserEntryModelImpl.MAPPING_TABLE_TBL_VIDEO_USER_NAME);
		}
	}

	/**
	 * Initializes the user entry persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.vn.com.fis.portal.model.UserEntry")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<UserEntry>> listenersList = new ArrayList<ModelListener<UserEntry>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<UserEntry>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}

		containsVideoEntry = new ContainsVideoEntry();

		addVideoEntry = new AddVideoEntry();
		clearVideoEntries = new ClearVideoEntries();
		removeVideoEntry = new RemoveVideoEntry();
	}

	public void destroy() {
		EntityCacheUtil.removeCache(UserEntryImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = CategoryEntryPersistence.class)
	protected CategoryEntryPersistence categoryEntryPersistence;
	@BeanReference(type = CategoryVideoEntryPersistence.class)
	protected CategoryVideoEntryPersistence categoryVideoEntryPersistence;
	@BeanReference(type = UserEntryPersistence.class)
	protected UserEntryPersistence userEntryPersistence;
	@BeanReference(type = VideoEntryPersistence.class)
	protected VideoEntryPersistence videoEntryPersistence;
	@BeanReference(type = VideoUserEntryPersistence.class)
	protected VideoUserEntryPersistence videoUserEntryPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	protected ContainsVideoEntry containsVideoEntry;
	protected AddVideoEntry addVideoEntry;
	protected ClearVideoEntries clearVideoEntries;
	protected RemoveVideoEntry removeVideoEntry;

	protected class ContainsVideoEntry {
		protected ContainsVideoEntry() {
			_mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
					_SQL_CONTAINSVIDEOENTRY,
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
					RowMapper.COUNT);
		}

		protected boolean contains(long userId, long videoId) {
			List<Integer> results = _mappingSqlQuery.execute(new Object[] {
						new Long(userId), new Long(videoId)
					});

			if (results.size() > 0) {
				Integer count = results.get(0);

				if (count.intValue() > 0) {
					return true;
				}
			}

			return false;
		}

		private MappingSqlQuery<Integer> _mappingSqlQuery;
	}

	protected class AddVideoEntry {
		protected AddVideoEntry() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"INSERT INTO tbl_video_user (userId, videoId) VALUES (?, ?)",
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
		}

		protected void add(long userId, long videoId) throws SystemException {
			if (!containsVideoEntry.contains(userId, videoId)) {
				ModelListener<vn.com.fis.portal.model.VideoEntry>[] videoEntryListeners =
					videoEntryPersistence.getListeners();

				for (ModelListener<UserEntry> listener : listeners) {
					listener.onBeforeAddAssociation(userId,
						vn.com.fis.portal.model.VideoEntry.class.getName(),
						videoId);
				}

				for (ModelListener<vn.com.fis.portal.model.VideoEntry> listener : videoEntryListeners) {
					listener.onBeforeAddAssociation(videoId,
						UserEntry.class.getName(), userId);
				}

				_sqlUpdate.update(new Object[] {
						new Long(userId), new Long(videoId)
					});

				for (ModelListener<UserEntry> listener : listeners) {
					listener.onAfterAddAssociation(userId,
						vn.com.fis.portal.model.VideoEntry.class.getName(),
						videoId);
				}

				for (ModelListener<vn.com.fis.portal.model.VideoEntry> listener : videoEntryListeners) {
					listener.onAfterAddAssociation(videoId,
						UserEntry.class.getName(), userId);
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	protected class ClearVideoEntries {
		protected ClearVideoEntries() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"DELETE FROM tbl_video_user WHERE userId = ?",
					new int[] { java.sql.Types.BIGINT });
		}

		protected void clear(long userId) throws SystemException {
			ModelListener<vn.com.fis.portal.model.VideoEntry>[] videoEntryListeners =
				videoEntryPersistence.getListeners();

			List<vn.com.fis.portal.model.VideoEntry> videoEntries = null;

			if ((listeners.length > 0) || (videoEntryListeners.length > 0)) {
				videoEntries = getVideoEntries(userId);

				for (vn.com.fis.portal.model.VideoEntry videoEntry : videoEntries) {
					for (ModelListener<UserEntry> listener : listeners) {
						listener.onBeforeRemoveAssociation(userId,
							vn.com.fis.portal.model.VideoEntry.class.getName(),
							videoEntry.getPrimaryKey());
					}

					for (ModelListener<vn.com.fis.portal.model.VideoEntry> listener : videoEntryListeners) {
						listener.onBeforeRemoveAssociation(videoEntry.getPrimaryKey(),
							UserEntry.class.getName(), userId);
					}
				}
			}

			_sqlUpdate.update(new Object[] { new Long(userId) });

			if ((listeners.length > 0) || (videoEntryListeners.length > 0)) {
				for (vn.com.fis.portal.model.VideoEntry videoEntry : videoEntries) {
					for (ModelListener<UserEntry> listener : listeners) {
						listener.onAfterRemoveAssociation(userId,
							vn.com.fis.portal.model.VideoEntry.class.getName(),
							videoEntry.getPrimaryKey());
					}

					for (ModelListener<vn.com.fis.portal.model.VideoEntry> listener : videoEntryListeners) {
						listener.onAfterRemoveAssociation(videoEntry.getPrimaryKey(),
							UserEntry.class.getName(), userId);
					}
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	protected class RemoveVideoEntry {
		protected RemoveVideoEntry() {
			_sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
					"DELETE FROM tbl_video_user WHERE userId = ? AND videoId = ?",
					new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
		}

		protected void remove(long userId, long videoId)
			throws SystemException {
			if (containsVideoEntry.contains(userId, videoId)) {
				ModelListener<vn.com.fis.portal.model.VideoEntry>[] videoEntryListeners =
					videoEntryPersistence.getListeners();

				for (ModelListener<UserEntry> listener : listeners) {
					listener.onBeforeRemoveAssociation(userId,
						vn.com.fis.portal.model.VideoEntry.class.getName(),
						videoId);
				}

				for (ModelListener<vn.com.fis.portal.model.VideoEntry> listener : videoEntryListeners) {
					listener.onBeforeRemoveAssociation(videoId,
						UserEntry.class.getName(), userId);
				}

				_sqlUpdate.update(new Object[] {
						new Long(userId), new Long(videoId)
					});

				for (ModelListener<UserEntry> listener : listeners) {
					listener.onAfterRemoveAssociation(userId,
						vn.com.fis.portal.model.VideoEntry.class.getName(),
						videoId);
				}

				for (ModelListener<vn.com.fis.portal.model.VideoEntry> listener : videoEntryListeners) {
					listener.onAfterRemoveAssociation(videoId,
						UserEntry.class.getName(), userId);
				}
			}
		}

		private SqlUpdate _sqlUpdate;
	}

	private static final String _SQL_SELECT_USERENTRY = "SELECT userEntry FROM UserEntry userEntry";
	private static final String _SQL_SELECT_USERENTRY_WHERE = "SELECT userEntry FROM UserEntry userEntry WHERE ";
	private static final String _SQL_COUNT_USERENTRY = "SELECT COUNT(userEntry) FROM UserEntry userEntry";
	private static final String _SQL_COUNT_USERENTRY_WHERE = "SELECT COUNT(userEntry) FROM UserEntry userEntry WHERE ";
	private static final String _SQL_GETVIDEOENTRIES = "SELECT {tbl_video.*} FROM tbl_video INNER JOIN tbl_video_user ON (tbl_video_user.videoId = tbl_video.videoId) WHERE (tbl_video_user.userId = ?)";
	private static final String _SQL_GETVIDEOENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM tbl_video_user WHERE userId = ?";
	private static final String _SQL_CONTAINSVIDEOENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM tbl_video_user WHERE userId = ? AND videoId = ?";
	private static final String _FINDER_COLUMN_SERVICEID_SERVICEID_2 = "userEntry.serviceId = ?";
	private static final String _FINDER_COLUMN_USERNAME_USERNAME_1 = "userEntry.userName IS NULL";
	private static final String _FINDER_COLUMN_USERNAME_USERNAME_2 = "userEntry.userName = ?";
	private static final String _FINDER_COLUMN_USERNAME_USERNAME_3 = "(userEntry.userName IS NULL OR userEntry.userName = ?)";
	private static final String _FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_1 = "userEntry.mobilePhone IS NULL";
	private static final String _FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_2 = "userEntry.mobilePhone = ?";
	private static final String _FINDER_COLUMN_MOBILEPHONE_MOBILEPHONE_3 = "(userEntry.mobilePhone IS NULL OR userEntry.mobilePhone = ?)";
	private static final String _ORDER_BY_ENTITY_ALIAS = "userEntry.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserEntry exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserEntry exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(UserEntryPersistenceImpl.class);
	private static UserEntry _nullUserEntry = new UserEntryImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<UserEntry> toCacheModel() {
				return _nullUserEntryCacheModel;
			}
		};

	private static CacheModel<UserEntry> _nullUserEntryCacheModel = new CacheModel<UserEntry>() {
			public UserEntry toEntityModel() {
				return _nullUserEntry;
			}
		};
}